home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / wemdemo4.zip / INFO / ELISP.8 < prev    next >
Text File  |  1994-09-21  |  50KB  |  1,250 lines

  1. Info file elisp, produced by Makeinfo, -*- Text -*- from input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual,   for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts
  10. Avenue,  Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of
  15. this manual provided the copyright notice and this permission notice
  16. are preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28.  
  29. 
  30. File: elisp,  Node: Function Cells,  Next: Related Topics,  Prev: Anonymous Functions,  Up: Functions
  31.  
  32. Accessing Function Cell Contents
  33. ================================
  34.  
  35.    The "function definition" of a symbol is the object stored in the
  36. function cell of the symbol.  The functions described here access,
  37. test, and set the function cell of symbols.
  38.  
  39.  * Function: symbol-function SYMBOL
  40.      This returns the object in the function cell of SYMBOL.  If the
  41.      symbol's function cell is void, a `void-function' error is
  42.      signaled.
  43.  
  44.      This function does not check that the returned object is a
  45.      legitimate function.
  46.  
  47.           (defun bar (n) (+ n 2))
  48.                => bar
  49.           (symbol-function 'bar)
  50.                => (lambda (n) (+ n 2))
  51.           (fset 'baz 'bar)
  52.                => bar
  53.           (symbol-function 'baz)
  54.                => bar
  55.  
  56.    If you have never given a symbol any function definition, we say
  57. that that symbol's function cell is "void".  In other words, the
  58. function cell does not have any Lisp object in it.  If you try to
  59. call such a symbol as a function, it signals a `void-function' error.
  60.  
  61.    Note that void is not the same as `nil' or the symbol `void'.  The
  62. symbols `nil' and `void' are Lisp objects, and can be stored into a
  63. function cell just as any other object can be (and they can be valid
  64. functions if you define them in turn with `defun'); but `nil' or
  65. `void' is *an object*.  A void function cell contains no object
  66. whatsoever.
  67.  
  68.    You can test the voidness of a symbol's function definition with
  69. `fboundp'.  After you have given a symbol a function definition, you
  70. can make it void once more using `fmakunbound'.
  71.  
  72.  * Function: fboundp SYMBOL
  73.      Returns `t' if the symbol has an object in its function cell,
  74.      `nil' otherwise.  It does not check that the object is a
  75.      legitimate function.
  76.  
  77.  * Function: fmakunbound SYMBOL
  78.      This function makes SYMBOL's function cell void, so that a
  79.      subsequent attempt to access this cell will cause a
  80.      `void-function' error.  (See also `makunbound', in *Note Local
  81.      Variables::.)
  82.  
  83.           (defun foo (x) x)
  84.                => x
  85.           (fmakunbound 'foo)
  86.                => x
  87.           (foo 1)
  88.           error--> Symbol's function definition is void: foo
  89.  
  90.  * Function: fset SYMBOL OBJECT
  91.      This function stores OBJECT in the function cell of SYMBOL.  The
  92.      result is OBJECT.  Normally OBJECT should be a function or the
  93.      name of a function, but this is not checked.
  94.  
  95.      There are three normal uses of this function:
  96.  
  97.         * Copying one symbol's function definition to another.  (In
  98.           other words, making an alternate name for a function.)
  99.  
  100.         * Giving a symbol a function definition that is not a list
  101.           and therefore cannot be made with `defun'.  *Note
  102.           Classifying Lists::, for an example of this usage.
  103.  
  104.         * In constructs for defining or altering functions.  If
  105.           `defun' were not a primitive, it could be written in Lisp
  106.           (as a macro) using `fset'.
  107.  
  108.      Here are examples of the first two uses:
  109.  
  110.           ;; Give `first' the same definition `car' has.
  111.           (fset 'first (symbol-function 'car))
  112.                => #<subr car>
  113.           (first '(1 2 3))
  114.                => 1
  115.           
  116.           ;; Make the symbol `car' the function definition of `xfirst'.
  117.           (fset 'xfirst 'car)
  118.                => car
  119.           (xfirst '(1 2 3))
  120.                => 1
  121.           (symbol-function 'xfirst)
  122.                => car
  123.           (symbol-function (symbol-function 'xfirst))
  124.                => #<subr car>
  125.  
  126.              ;; Define a named keyboard macro.
  127.           (fset 'kill-two-lines "\^u2\^k")
  128.                => "\^u2\^k"
  129.  
  130.    When writing a function that extends a previously defined
  131. function, the following idiom is often used:
  132.  
  133.      (fset 'old-foo (symbol-function 'foo))
  134.      
  135.      (defun foo ()
  136.        "Just like old-foo, except more so."
  137.        (old-foo)
  138.        (more-so))
  139.  
  140. This does not work properly if `foo' has been defined to autoload. 
  141. In such a case, when `foo' calls `old-foo', Lisp will attempt to
  142. define `old-foo' by loading a file.  Since this presumably defines
  143. `foo' rather than `old-foo', it will not produce the proper results. 
  144. The only way to avoid this problem is to make sure the file is loaded
  145. before moving aside the old definition of `foo'.
  146.  
  147.  
  148. 
  149. File: elisp,  Node: Related Topics,  Prev: Function Cells,  Up: Functions
  150.  
  151. Other Topics Related to Functions
  152. =================================
  153.  
  154.    Here is a table of several functions that do things related to
  155. function calling and function definitions.
  156.  
  157. `apply'
  158.      *Note Calling Functions::.
  159.  
  160. `autoload'
  161.      *Note Autoload::.
  162.  
  163. `call-interactively'
  164.      *Note Interactive Call::.
  165.  
  166. `commandp'
  167.      *Note Interactive Call::.
  168.  
  169. `documentation'
  170.      *Note Accessing Documentation::.
  171.  
  172. `eval'
  173.      *Note Eval::.
  174.  
  175. `funcall'
  176.      *Note Calling Functions::.
  177.  
  178. `ignore'
  179.      *Note Calling Functions::.
  180.  
  181. `interactive'
  182.      *Note Using Interactive::.
  183.  
  184. `interactive-p'
  185.      *Note Interactive Call::.
  186.  
  187. `mapatoms'
  188.      *Note Creating Symbols::.
  189.  
  190. `mapcar'
  191.      *Note Mapping Functions::.
  192.  
  193. `mapconcat'
  194.      *Note Mapping Functions::.
  195.  
  196. `undefined'
  197.      *Note Key Lookup::.
  198.  
  199.  
  200. 
  201. File: elisp,  Node: Macros,  Next: Loading,  Prev: Functions,  Up: Top
  202.  
  203. Macros
  204. ******
  205.  
  206.    "Macros" enable you to define new control constructs and other
  207. language features.  A macro is defined much like a function, but
  208. instead of telling how to compute a value, it tells how to compute
  209. another Lisp expression which will in turn compute the value.  We
  210. call this expression the "expansion" of the macro.
  211.  
  212.    Macros can do this because they operate on the unevaluated
  213. expressions for the arguments, not on the argument values as
  214. functions do.  They can therefore construct an expansion containing
  215. these argument expressions or parts of them.
  216.  
  217. * Menu:
  218.  
  219. * Simple Macro::            A basic example.
  220. * Expansion::               How, when and why macros are expanded.
  221. * Compiling Macros::        How macros are expanded by the compiler.
  222. * Defining Macros::         How to write a macro definition.
  223. * Backquote::               Easier construction of list structure.
  224. * Problems with Macros::    Don't evaluate the macro arguments too many times.
  225.                               Don't hide the user's variables.
  226.  
  227.  
  228. 
  229. File: elisp,  Node: Simple Macro,  Next: Expansion,  Prev: Macros,  Up: Macros
  230.  
  231. A Simple Example of a Macro
  232. ===========================
  233.  
  234.    Suppose we would like to define a Lisp construct to increment a
  235. variable value, much like the `++' operator in C.  We would like to
  236. write `(inc x)' and have the effect of `(setq x (1+ x))'.  Here's a
  237. macro definition that will do the job:
  238.  
  239.      (defmacro inc (var)
  240.         (list 'setq var (list '1+ var)))
  241.  
  242.    When this is called with `(inc x)', the argument `var' has the
  243. value `x'--*not* the *value* of `x'.  The body of the macro uses this
  244. to construct the expansion, which is `(setq x (1+ x))'.  Once the
  245. macro definition returns this expansion, Lisp proceeds to evaluate
  246. it, thus incrementing `x'.
  247.  
  248.  
  249. 
  250. File: elisp,  Node: Expansion,  Next: Compiling Macros,  Prev: Simple Macro,  Up: Macros
  251.  
  252. Expansion of a Macro Call
  253. =========================
  254.  
  255.    A macro call looks just like a function call in that it is a list
  256. which starts with the name of the macro.  The rest of the elements of
  257. the list are the arguments of the macro.
  258.  
  259.    Evaluation of the macro call begins like evaluation of a function
  260. call except for one crucial difference: the macro arguments are the
  261. actual expressions appearing in the macro call.  They are not
  262. evaluated before they are given to the macro definition.  By
  263. contrast, the arguments of a function are results of evaluating the
  264. elements of the function call list.
  265.  
  266.    Having obtained the arguments, Lisp invokes the macro definition
  267. just as a function is invoked.  The argument variables of the macro
  268. are bound to the argument values from the macro call, or to a list of
  269. them in the case of a `&rest' argument.  And the macro body executes
  270. and returns its value just as a function body does.
  271.  
  272.    The second crucial difference between macros and functions is that
  273. the value returned by the macro body is not the value of the macro
  274. call.  Instead, it is an alternate expression for computing that
  275. value, also known as the "expansion" of the macro.  The Lisp
  276. interpreter proceeds to evaluate the expansion as soon as it comes
  277. back from the macro.
  278.  
  279.    Since the expansion is evaluated in the normal manner, it may
  280. contain calls to other macros.  It may even be a call to the same
  281. macro, though this is unusual.
  282.  
  283.    You can see the expansion of a given macro call by calling
  284. `macroexpand':
  285.  
  286.  * Function: macroexpand FORM &optional ENVIRONMENT
  287.      This function expands FORM, if it is a macro call.  If the
  288.      result is another macro call, it is expanded in turn, until
  289.      something which is not a macro call results.  That is the value
  290.      returned by `macroexpand'.  If FORM is not a macro call to begin
  291.      with, it is returned as given.
  292.  
  293.      Note that `macroexpand' does not look at the subexpressions of
  294.      FORM (although some macro definitions may do so).  If they are
  295.      macro calls themselves, `macroexpand' will not expand them.
  296.  
  297.      If ENVIRONMENT is provided, it specifies an alist of macro
  298.      definitions that shadow the currently defined macros.  This is
  299.      used by byte compilation.
  300.  
  301.           (defmacro inc (var)
  302.               (list 'setq var (list '1+ var)))
  303.                => inc
  304.           
  305.           (macroexpand '(inc r))
  306.                => (setq r (1+ r))
  307.           
  308.           (defmacro inc2 (var1 var2)
  309.               (list 'progn (list 'inc var1) (list 'inc var2)))
  310.                => inc2
  311.           
  312.           (macroexpand '(inc2 r s))
  313.                => (progn (inc r) (inc s))        ; `inc' not expanded here.
  314.  
  315.  
  316. 
  317. File: elisp,  Node: Compiling Macros,  Next: Defining Macros,  Prev: Expansion,  Up: Macros
  318.  
  319. Macros and Byte Compilation
  320. ===========================
  321.  
  322.    You might ask why we take the trouble to compute an expansion for
  323. a macro and then evaluate the expansion.  Why not have the macro body
  324. produce the desired results directly?  The reason has to do with
  325. compilation.
  326.  
  327.    When a macro call appears in a Lisp program being compiled, the
  328. Lisp compiler calls the macro definition just as the interpreter
  329. would, and receives an expansion.  But instead of evaluating this
  330. expansion, it compiles expansion as if it had appeared directly in
  331. the program.  As a result, the compiled code produces the value and
  332. side effects intended for the macro, but executes at full compiled
  333. speed.  This would not work if the macro body computed the value and
  334. side effects itself--they would be computed at compile time, which is
  335. not useful.
  336.  
  337.    In order for compilation of macro calls to work, the macros must
  338. be defined in Lisp when the calls to them are compiled.  The compiler
  339. has a special feature to help you do this: if a file being compiled
  340. contains a `defmacro' form, the macro is defined temporarily for the
  341. rest of the compilation of that file.  To use this feature, you must
  342. define the macro in the same file where it is used and before its
  343. first use.
  344.  
  345.    While byte-compiling a file, any `require' calls at top-level are
  346. executed.  One way to ensure that necessary macro definitions are
  347. available during compilation is to require the file that defines them.
  348. *Note Features::.
  349.  
  350.  
  351. 
  352. File: elisp,  Node: Defining Macros,  Next: Backquote,  Prev: Compiling Macros,  Up: Macros
  353.  
  354. Defining Macros
  355. ===============
  356.  
  357.    A Lisp macro is a list whose CAR is `macro'.  Its CDR should be a
  358. function; expansion of the macro works by applying the function (with
  359. `apply') to the list of unevaluated argument-expressions from the
  360. macro call.
  361.  
  362.    It is possible to use an anonymous Lisp macro just like an
  363. anonymous function, but this is never done, because it does not make
  364. sense to pass an anonymous macro to mapping functions such as
  365. `mapcar'.  In practice, all Lisp macros have names, and they are
  366. usually defined with the special form `defmacro'.
  367.  
  368.  * Special Form: defmacro NAME ARGUMENT-LIST BODY-FORMS...
  369.      `defmacro' defines the symbol NAME as a macro that looks like
  370.      this:
  371.  
  372.           (macro lambda ARGUMENT-LIST . BODY-FORMS)
  373.  
  374.      This macro object is stored in the function cell of NAME.  The
  375.      value returned by evaluating the `defmacro' form is NAME, but
  376.      usually we ignore this value.
  377.  
  378.      The shape and meaning of ARGUMENT-LIST is the same as in a
  379.      function, and the keywords `&rest' and `&optional' may be used
  380.      (*note Argument List::.).  Macros may have a documentation
  381.      string, but any `interactive' declaration is ignored since
  382.      macros cannot be called interactively.
  383.  
  384.  
  385. 
  386. File: elisp,  Node: Backquote,  Next: Problems with Macros,  Prev: Defining Macros,  Up: Macros
  387.  
  388. Backquote
  389. =========
  390.  
  391.    It could prove rather awkward to write macros of significant size,
  392. simply due to the number of times the function `list' needs to be
  393. called.  To make writing these forms easier, a macro ``' (often
  394. called "backquote") exists.
  395.  
  396.    Backquote allows you to quote a list, but selectively evaluate
  397. elements of that list.  In the simplest case, it is identical to the
  398. special form `quote' (*note Quoting::.).  For example, these two
  399. forms yield identical results:
  400.  
  401.      (` (a list of (+ 2 3) elements))
  402.           => (a list of (+ 2 3) elements)
  403.      (quote (a list of (+ 2 3) elements))
  404.           => (a list of (+ 2 3) elements)
  405.  
  406.    By inserting a special marker, `,', inside of the argument to
  407. backquote, it is possible to evaluate desired portions of the argument:
  408.  
  409.      (list 'a 'list 'of (+ 2 3) 'elements)
  410.           => (a list of 5 elements)
  411.      (` (a list of (, (+ 2 3)) elements))
  412.           => (a list of 5 elements)
  413.  
  414.    It is also possible to have an evaluated list "spliced" into the
  415. resulting list by using the special marker `,@'.  The elements of the
  416. spliced list become elements at the same level as the other elements
  417. of the resulting list.  The equivalent code without using ``' is
  418. often unreadable.  Here are some examples:
  419.  
  420.      (setq some-list '(2 3))
  421.           => (2 3)
  422.      (cons 1 (append some-list '(4) some-list))
  423.           => (1 2 3 4 2 3)
  424.      (` (1 (,@ some-list) 4 (,@ some-list)))
  425.           => (1 2 3 4 2 3)
  426.      
  427.      (setq list '(hack foo bar))
  428.           => (hack foo bar)
  429.      (cons 'use
  430.        (cons 'the
  431.          (cons 'words (append (cdr list) '(as elements)))))
  432.           => (use the words foo bar as elements)
  433.      (` (use the words (,@ (cdr list)) as elements (,@ nil)))
  434.           => (use the words foo bar as elements)
  435.  
  436.    The reason for `(,@ nil)' is to avoid a bug in Emacs version 18. 
  437. The bug occurs when a call to `,@' is followed only by constant
  438. elements.  Thus,
  439.  
  440.      (` (use the words (,@ (cdr list)) as elements))
  441.  
  442. would not work, though it really ought to.  `(,@ nil)' avoids the
  443. problem by being a nonconstant element that does not affect the result.
  444.  
  445.  * Macro: ` LIST
  446.      This macro returns LIST as `quote' would, except that the list
  447.      is copied each time this expression is evaluated, and any
  448.      sublist of the form `(, SUBEXP)' is replaced by the value of
  449.      SUBEXP.  Any sublist of the form `(,@ LISTEXP)' is replaced by
  450.      evaluating LISTEXP and splicing its elements into the containing
  451.      list in place of this sublist.  (A single sublist can in this
  452.      way be replaced by any number of new elements in the containing
  453.      list.)
  454.  
  455.      There are certain contexts in which `,' would not be recognized
  456.      and should not be used:
  457.  
  458.           ;; Use of a `,' expression as the CDR of a list.
  459.           (` (a . (, 1)))                                 ; Not `(a . 1)'
  460.                => (a \, 1)                                
  461.           
  462.           ;; Use of `,' in a vector.
  463.           (` [a (, 1) c])                                 ; Not `[a 1 c]'
  464.                error--> Wrong type argument                      
  465.           
  466.           ;; Use of a `,' as the entire argument of ``'.
  467.           (` (, 2))                                       ; Not 2
  468.                => (\, 2)
  469.  
  470.      Common Lisp note: in Common Lisp, `,' and `,@' are implemented
  471.      as reader macros, so they do not require parentheses.  Emacs
  472.      Lisp implements them as functions because reader macros are not
  473.      supported (to save space).
  474.  
  475.  
  476. 
  477. File: elisp,  Node: Problems with Macros,  Prev: Backquote,  Up: Macros
  478.  
  479. Common Problems Using Macros
  480. ============================
  481.  
  482.    The basic facts of macro expansion have all been described above,
  483. but there consequences are often counterintuitive.  This section
  484. describes some important consequences that can lead to trouble, and
  485. rules to follow to avoid trouble.
  486.  
  487. * Menu:
  488.  
  489. * Argument Evaluation::    The expansion should evaluate each macro arg once.
  490. * Surprising Local Vars::  Local variable bindings in the expansion
  491.                               require special care.
  492. * Eval During Expansion::  Don't evaluate them; put them in the expansion.
  493. * Repeated Expansion::     Avoid depending on how many times expansion is done.
  494.  
  495.  
  496. 
  497. File: elisp,  Node: Argument Evaluation,  Next: Surprising Local Vars,  Prev: Problems with Macros,  Up: Problems with Macros
  498.  
  499. Evaluating Macro Arguments Too Many Times
  500. -----------------------------------------
  501.  
  502.    When defining a macro you must pay attention to the number of
  503. times the arguments will be evaluated when the expansion is executed.
  504. The following macro (used to facilitate iteration) illustrates the
  505. problem.  This macro allows us to write a simple "for" loop such as
  506. one might find in Pascal.
  507.  
  508.      (defmacro for (var from init to final do &rest body)
  509.        "Execute a simple \"for\" loop, e.g.,
  510.          (for i from 1 to 10 do (print i))."
  511.        (list 'let (list (list var init))
  512.              (cons 'while (cons (list '<= var final)
  513.                                 (append body (list (list 'inc var)))))))
  514.      => for
  515.      
  516.      (for i from 1 to 3 do
  517.         (setq square (* i i))
  518.         (princ (format "\n%d %d" i square)))
  519.      ==>
  520.      (let ((i 1))
  521.        (while (<= i 3)
  522.          (setq square (* i i))
  523.          (princ (format "%d      %d" i square))
  524.          (inc i)))
  525.      
  526.           -|1       1
  527.           -|2       4
  528.           -|3       9
  529.      => nil
  530.  
  531. (The arguments `from', `to', and `do' in this macro are "syntactic
  532. sugar"; they are entirely ignored.  The idea is that you will write
  533. noise words (such as `from', `to', and `do') in those positions in
  534. the macro call.)
  535.  
  536.    This macro suffers from the defect that FINAL is evaluated on
  537. every iteration.  If FINAL is a constant, this is not a problem.  If
  538. it is a more complex form, say `(long-complex-calculation x)', this
  539. can slow down the execution significantly.  If FINAL has side
  540. effects, executing it more than once is probably incorrect.
  541.  
  542.    A well-designed macro definition takes steps to avoid this problem
  543. by producing an expansion that evaluates the argument expressions
  544. exactly once unless repeated evaluation is part of the intended
  545. purpose of the macro.  Here is a correct expansion for the `for' macro:
  546.  
  547.      (let ((i 1)
  548.            (max 3))
  549.        (while (<= i max)
  550.          (setq square (* i i))
  551.          (princ (format "%d      %d" i square))
  552.          (inc i)))
  553.  
  554.    Here is a macro definition that creates this expansion:
  555.  
  556.      (defmacro for (var from init to final do &rest body)
  557.        "Execute a simple for loop: (for i from 1 to 10 do (print i))."
  558.        (` (let (((, var) (, init))
  559.                 (max (, final)))
  560.             (while (<= (, var) max)
  561.               (,@ body)
  562.               (inc (, var))))))
  563.  
  564.    Unfortunately, this introduces another problem.
  565.  
  566.    Proceed to the following node.
  567.  
  568.  
  569. 
  570. File: elisp,  Node: Surprising Local Vars,  Next: Eval During Expansion,  Prev: Argument Evaluation,  Up: Problems with Macros
  571.  
  572. Local Variables in Macro Expansions
  573. -----------------------------------
  574.  
  575.    In the previous section, the definition of `for' was fixed as
  576. follows to make the expansion evaluate the macro arguments the proper
  577. number of times:
  578.  
  579.      (defmacro for (var from init to final do &rest body)
  580.        "Execute a simple for loop: (for i from 1 to 10 do (print i))."
  581.        (` (let (((, var) (, init))
  582.                 (max (, final)))
  583.             (while (<= (, var) max)
  584.               (,@ body)
  585.               (inc (, var))))))
  586.  
  587.    The new definition of `for' has a new problem: it introduces a
  588. local variable named `max' which the user does not expect.  This will
  589. cause trouble in examples such as the following:
  590.  
  591.      (let ((max 0))
  592.        (for x from 0 to 10 do
  593.          (let ((this (frob x)))
  594.            (if (< max this)
  595.                (setq max this)))))
  596.  
  597. The references to `max' inside the body of the `for', which are
  598. supposed to refer to the user's binding of `max', will instead access
  599. the binding made by `for'.
  600.  
  601.    The way to correct this is to use an uninterned symbol instead of
  602. `max' (*note Creating Symbols::.).  The uninterned symbol can be
  603. bound and referred to just like any other symbol, but since it is
  604. created by `for', we know that it cannot appear in the user's program.
  605. Since it is not interned, there is no way the user can put it into
  606. the program later.  It will not appear anywhere except where put by
  607. `for'.  Here is a definition of `for' which works this way:
  608.  
  609.      (defmacro for (var from init to final do &rest body)
  610.        "Execute a simple for loop: (for i from 1 to 10 do (print i))."
  611.        (let ((tempvar (make-symbol "max")))
  612.          (` (let (((, var) (, init))
  613.                   ((, tempvar) (, final)))
  614.               (while (<= (, var) (, tempvar))
  615.                      (,@ body)
  616.                      (inc (, var)))))))
  617.  
  618. This creates an uninterned symbol named `max' and puts it in the
  619. expansion instead of the usual interned symbol `max' that appears in
  620. expressions ordinarily.
  621.  
  622.  
  623. 
  624. File: elisp,  Node: Eval During Expansion,  Next: Repeated Expansion,  Prev: Surprising Local Vars,  Up: Problems with Macros
  625.  
  626. Evaluating Macro Arguments in Expansion
  627. ---------------------------------------
  628.  
  629.    Another problem can happen if you evaluate any of the macro
  630. argument expressions during the computation of the expansion, such as
  631. by calling `eval' (*note Eval::.).  If the argument is supposed to
  632. refer to the user's variables, you may have trouble if the user
  633. happens to use a variable with the same name as one of the macro
  634. arguments.  Inside the macro body, the macro argument binding is the
  635. most local binding of this variable, so any references inside the
  636. form being evaluated will refer to it.  Here is an example:
  637.  
  638.      (defmacro foo (a)
  639.        (list 'setq (eval a) t))
  640.           => foo
  641.      (setq x 'b)
  642.      (foo x) ==> (setq b t)
  643.           => t                  ; and `b' has been set.
  644.      ;; but
  645.      (setq a 'b)
  646.      (foo a) ==> (setq 'b t)     ; invalid!
  647.      error--> Symbol's value is void: b
  648.  
  649.    It makes a difference whether the user types `a' or `x', because
  650. `a' conflicts with the macro argument variable `a'.
  651.  
  652.    In general it is best to avoid calling `eval' in a macro
  653. definition at all.
  654.  
  655.  
  656. 
  657. File: elisp,  Node: Repeated Expansion,  Prev: Eval During Expansion,  Up: Problems with Macros
  658.  
  659. How Many Times is the Macro Expanded?
  660. -------------------------------------
  661.  
  662.    Occasionally problems result from the fact that a macro call is
  663. expanded each time it is evaluated in an interpreted function, but is
  664. expanded only once (during compilation) for a compiled function.  If
  665. the macro definition has side effects, they will work differently
  666. depending on how many times the macro is expanded.
  667.  
  668.    In particular, constructing objects is a kind of side effect.  If
  669. the macro is called once, then the objects are constructed only once.
  670. In other words, the same structure of objects is used each time the
  671. macro call is executed.  In interpreted operation, the macro is
  672. reexpanded each time, producing a fresh collection of objects each
  673. time.  Usually this does not matter--the objects have the same
  674. contents whether they are shared or not.  But if the surrounding
  675. program does side effects on the objects, it makes a difference
  676. whether they are shared.  Here is an example:
  677.  
  678.      (defmacro new-object ()
  679.        (list 'quote (cons nil nil)))
  680.      
  681.      (defun initialize (condition)
  682.        (let ((object (new-object)))
  683.          (if condition
  684.          (setcar object condition))
  685.          object))
  686.  
  687. If `initialize' is interpreted, a new list `(nil)' is constructed
  688. each time `initialize' is called.  Thus, no side-effect survives
  689. between calls.  If `initialize' is compiled, then the macro
  690. `new-object' is expanded during compilation, producing a single
  691. "constant" `(nil)' that is reused and altered each time `initialize'
  692. is called.
  693.  
  694.  
  695. 
  696. File: elisp,  Node: Loading,  Next: Byte Compilation,  Prev: Macros,  Up: Top
  697.  
  698. Loading
  699. *******
  700.  
  701.    Loading a file of Lisp code means bringing its contents into the
  702. Lisp environment in the form of Lisp objects.  Emacs finds and opens
  703. the file, reads the text, evaluates each form, and then closes the
  704. file.
  705.  
  706.    The load functions evaluate all the expressions in a file just as
  707. the `eval-current-buffer' function evaluates all the expressions in a
  708. buffer.  The difference is that the load functions read and evaluate
  709. the text in the file as found on disk, not the text in an Emacs buffer.
  710.  
  711.    The loaded file must contain Lisp expressions, either as source
  712. code or, optionally, as byte-compiled code.  Each form in the file is
  713. called a "top-level form".  There is no special format for the forms
  714. in a loadable file; any form in a file may equally well be typed
  715. directly into a buffer and evaluated there.  (Indeed, most code is
  716. tested this way.)  Most often, the forms are function definitions and
  717. variable definitions.
  718.  
  719.    A file containing Lisp code is often called a "library".  Thus,
  720. the "Rmail library" is a file containing code for Rmail mode. 
  721. Similarly, a "Lisp library directory" is a directory of files
  722. containing Lisp code.
  723.  
  724. * Menu:
  725.  
  726. * How Programs Do Loading::     The `load' function and others.
  727. * Autoload::                    Setting up a function to autoload.
  728. * Repeated Loading::            Precautions about loading a file twice.
  729. * Features::                    Loading a library if it isn't already loaded.
  730.  
  731.  
  732. 
  733. File: elisp,  Node: How Programs Do Loading,  Next: Autoload,  Prev: Loading,  Up: Loading
  734.  
  735. How Programs Do Loading
  736. =======================
  737.  
  738.    There are several interface functions for loading.  For example,
  739. the `autoload' function creates a Lisp object that loads a file when
  740. it is evaluated (*note Autoload::.).  `require' also causes files to
  741. be loaded (*note Features::.).  Ultimately, all these facilities call
  742. the `load' function to do the work.
  743.  
  744.  * Function: load FILENAME &optional MISSING-OK NOMESSAGE NOSUFFIX
  745.      This function finds and opens a file of Lisp code, evaluates all
  746.      the forms in it, and closes the file.
  747.  
  748.      To find the file, `load' first looks for a file named
  749.      `FILENAME.elc', that is, for a file whose name has `.elc'
  750.      appended.  If such a file exists, it is loaded.  But if there is
  751.      no file by that name, then `load' looks for a file whose name
  752.      has `.el' appended.  If that file exists, it is loaded. 
  753.      Finally, if there is no file by either name, `load' looks for a
  754.      file named FILENAME with nothing appended, and loads it if it
  755.      exists.  (The `load' function is not clever about looking at
  756.      FILENAME.  In the perverse case of a file named `foo.el.el',
  757.      evaluation of `(load "foo.el")' will indeed find it.)
  758.  
  759.      If the optional argument NOSUFFIX is non-`nil', then the
  760.      suffixes `.elc' and `.el' are not tried.  In this case, the file
  761.      name must be specified precisely.
  762.  
  763.      If FILENAME is a relative file name, such as `foo.bar' or
  764.      `baz/foo.bar', Emacs searches for the file using the variable
  765.      `load-path'.  Emacs does this by appending FILENAME to each of
  766.      the directories listed in `load-path', and loading the first
  767.      file it finds whose name matches.  The current default directory
  768.      is tried only if it is specified in `load-path', where it is
  769.      represented as `nil'.  All three possible suffixes are tried in
  770.      the first directory in `load-path', then all three in the second
  771.      directory in `load-path', etc.
  772.  
  773.      Messages like `Loading foo...' and `Loading foo...done' are
  774.      printed in the echo area while loading unless NOMESSAGE is
  775.      non-`nil'.
  776.  
  777.      Any errors that are encountered while loading a file cause
  778.      `load' to abort.  If the load was done for the sake of
  779.      `autoload', certain kinds of top-level forms, those which define
  780.      functions, are undone.
  781.  
  782.      The error `file-error' is signaled (with `Cannot open load file
  783.      FILENAME') if no file is found.  No error is signaled if
  784.      MISSING-OK is non-`nil'--then `load' just returns `nil'.
  785.  
  786.      `load' returns `t' if the file loads successfully.
  787.  
  788.  * User Option: load-path
  789.      The value of this variable is a list of directories to search
  790.      when loading files with `load'.  Each element is a string (which
  791.      must be a directory name) or `nil' (which stands for the current
  792.      working directory).  The value of `load-path' is initialized
  793.      from the environment variable `EMACSLOADPATH', if it exists;
  794.      otherwise it is set to the default specified in
  795.      `emacs/src/paths.h' when Emacs is built.
  796.  
  797.      The syntax of `EMACSLOADPATH' is the same as that of `PATH';
  798.      fields are separated by `:', and `.' is used for the current
  799.      default directory.  Here is an example of how to set your
  800.      `EMACSLOADPATH' variable from a `csh' `.login' file:
  801.  
  802.           setenv EMACSLOADPATH .:/user/liberte/emacs:/usr/local/lib/emacs/lisp
  803.  
  804.      Here is how to set it using `sh':
  805.  
  806.           export EMACSLOADPATH
  807.           EMACSLOADPATH=.:/user/liberte/emacs:/usr/local/lib/emacs/lisp
  808.  
  809.      Here is an example of code you can place in a `.emacs' file to
  810.      add several directories to the front of your default `load-path':
  811.  
  812.           (setq load-path
  813.                 (append
  814.                  (list nil
  815.                        "/user/liberte/emacs"
  816.                        "/usr/local/lisplib")
  817.                  load-path))
  818.  
  819.      In this example, the path searches the current working directory
  820.      first, followed by `/user/liberte/emacs' and
  821.      `/usr/local/lisplib', which are then followed by the standard
  822.      directories for Lisp code.
  823.  
  824.      When Emacs 18 is processing command options `-l' or `-load'
  825.      which specify Lisp libraries to be loaded, it temporarily adds
  826.      the current directory to the front of `load-path' so that files
  827.      in the current directory can be specified easily.  Emacs version
  828.      19 will also find such files in the current directory but
  829.      without altering `load-path'.
  830.  
  831.  * Variable: load-in-progress
  832.      This variable is non-`nil' if Emacs is in the process of loading
  833.      a file, and it is `nil' otherwise.  This is how `defun' and
  834.      `provide' determine whether a load is in progress, so that their
  835.      effect can be undone if the load fails.
  836.  
  837.    To learn how `load' is used to build Emacs, see *Note Building
  838. Emacs::.
  839.  
  840.  
  841. 
  842. File: elisp,  Node: Autoload,  Next: Repeated Loading,  Prev: How Programs Do Loading,  Up: Loading
  843.  
  844. Autoload
  845. ========
  846.  
  847.    The "autoload" facility allows you to make a function or macro
  848. available but put off loading its actual definition.  An attempt to
  849. call a symbol whose definition is an autoload object automatically
  850. reads the file to install the real definition and its other
  851. associated code, and then calls the real definition.
  852.  
  853.    To prepare a function or macro for autoloading, you must call
  854. `autoload', specifying the function name and the name of the file to
  855. be loaded.  This is usually done when Emacs is first built, by files
  856. such as `emacs/lisp/loaddefs.el'.
  857.  
  858.    The following example shows how `doctor' is prepared for
  859. autoloading in `loaddefs.el':
  860.  
  861.      (autoload 'doctor "doctor"
  862.        "\
  863.      Switch to *doctor* buffer and start giving psychotherapy."
  864.        t)
  865.  
  866. The backslash and newline immediately following the double-quote are
  867. a convention used only in the preloaded Lisp files such as
  868. `loaddefs.el'; they cause the documentation string to be put in the
  869. `etc/DOC' file.  (*Note Building Emacs::.)  In any other source file,
  870. you would write just this:
  871.  
  872.      (autoload 'doctor "doctor"
  873.        "Switch to *doctor* buffer and start giving psychotherapy."
  874.        t)
  875.  
  876.    Calling `autoload' creates an autoload object containing the name
  877. of the file and some other information, and makes this the definition
  878. of the specified symbol.  When you later try to call that symbol as a
  879. function or macro, the file is loaded; the loading should redefine
  880. that symbol with its proper definition.  After the file completes
  881. loading, the function or macro is called as if it had been there
  882. originally.
  883.  
  884.    If, at the end of loading the file, the desired Lisp function or
  885. macro has not been defined, then the error `error' is signaled (with
  886. data `"Autoloading failed to define function FUNCTION-NAME"').
  887.  
  888.    The autoloaded file may, of course, contain other definitions and
  889. may require or provide one or more features.  If the file is not
  890. completely loaded (due to an error in the evaluation of the contents)
  891. any function definitions or `provide' calls that occurred during the
  892. load are undone.  This is to ensure that the next attempt to call any
  893. function autoloading from this file will try again to load the file. 
  894. If not for this, then some of the functions in the file might appear
  895. defined, but they may fail to work properly for the lack of certain
  896. subroutines defined later in the file and not loaded successfully.
  897.  
  898.  * Function: autoload SYMBOL FILENAME &optional DOCSTRING INTERACTIVE
  899.           MACRO
  900.      This function defines the function (or macro) named SYMBOL so as
  901.      to load automatically from FILENAME.  The string FILENAME is a
  902.      file name which will be passed to `load' when the function is
  903.      called.
  904.  
  905.      The argument DOCSTRING is the documentation string for the
  906.      function.  Normally, this is the same string that is in the
  907.      function definition itself.  This makes it possible to look at
  908.      the documentation without loading the real definition.
  909.  
  910.      If INTERACTIVE is non-`nil', then the function can be called
  911.      interactively.  This lets completion in `M-x' work without
  912.      loading the function's real definition.  The complete
  913.      interactive specification need not be given here.  If MACRO is
  914.      non-`nil', then the function is really a macro.
  915.  
  916.      If SYMBOL already has a non-`nil' function definition that is
  917.      not an autoload object, `autoload' does nothing and returns
  918.      `nil'.  If the function cell of SYMBOL is void, or is already an
  919.      autoload object, then it is set to an autoload object that looks
  920.      like this:
  921.  
  922.           (autoload FILENAME DOCSTRING INTERACTIVE MACRO)
  923.  
  924.      For example,
  925.  
  926.           (symbol-function 'run-prolog)
  927.                => (autoload "prolog" 169681 t nil)
  928.  
  929.      In this case, `"prolog"' is the name of the file to load, 169681
  930.      is the reference to the documentation string in the
  931.      `emacs/etc/DOC' file (*note Documentation Basics::.), `t' means
  932.      the function is interactive, and `nil' that it is not a macro.
  933.  
  934.  
  935. 
  936. File: elisp,  Node: Repeated Loading,  Next: Features,  Prev: Autoload,  Up: Loading
  937.  
  938. Repeated Loading
  939. ================
  940.  
  941.    You may load a file more than once in an Emacs session.  For
  942. example, after you have rewritten and reinstalled a function
  943. definition by editing it in a buffer, you may wish to return to the
  944. original version; you can do this by reloading the file in which it
  945. is located.
  946.  
  947.    When you load or reload files, bear in mind that the `load' and
  948. `load-library' functions automatically load a byte-compiled file
  949. rather than a non-compiled file of similar name.  If you rewrite a
  950. file that you intend to save and reinstall, remember to byte-compile
  951. it if necessary; otherwise you may find yourself inadvertently
  952. reloading the older, byte-compiled file instead of your newer,
  953. non-compiled file!
  954.  
  955.    When writing the forms in a library, keep in mind that the library
  956. might be loaded more than once.  For example, the choice of `defvar'
  957. vs. `defconst' for defining a variable depends on whether it is
  958. desirable to reinitialize the variable if the library is reloaded:
  959. `defconst' does so, and `defvar' does not.  (*Note Defining
  960. Variables::.)
  961.  
  962.    The simplest way to add an element to an alist is like this:
  963.  
  964.      (setq minor-mode-alist (cons '(leif-mode " Leif") minor-mode-alist))
  965.  
  966. But this would add multiple elements if the library is reloaded.  To
  967. avoid the problem, write this:
  968.  
  969.      (or (assq 'leif-mode minor-mode-alist)
  970.          (setq minor-mode-alist
  971.                (cons '(leif-mode " Leif") minor-mode-alist)))
  972.  
  973.    Occasionally you will want to test explicitly whether a library
  974. has already been loaded; you can do so as follows:
  975.  
  976.      (if (not (boundp 'foo-was-loaded))
  977.          EXECUTE-FIRST-TIME-ONLY)
  978.      
  979.      (setq foo-was-loaded t)
  980.  
  981.  
  982. 
  983. File: elisp,  Node: Features,  Prev: Repeated Loading,  Up: Loading
  984.  
  985. Features
  986. ========
  987.  
  988.    `provide' and `require' are an alternative to `autoload' for
  989. loading files automatically.  They work in terms of named "features".
  990. Autoloading is triggered by calling a specific function, but a
  991. feature is loaded the first time another program asks for it by name.
  992.  
  993.    The use of named features simplifies the task of determining
  994. whether required definitions have been defined.  A feature name is a
  995. symbol that stands for a collection of functions, variables, etc.  A
  996. program that needs the collection may ensure that they are defined by
  997. "requiring" the feature.  If the file that contains the feature has
  998. not yet been loaded, then it will be loaded (or an error will be
  999. signaled if it cannot be loaded).  The file thus loaded must
  1000. "provide" the required feature or an error will be signaled.
  1001.  
  1002.    To require the presence of a feature, call `require' with the
  1003. feature name as argument.  `require' looks in the global variable
  1004. `features' to see whether the desired feature has been provided
  1005. already.  If not, it loads the feature from the appropriate file. 
  1006. This file should call `provide' at the top-level to add the feature
  1007. to `features'.
  1008.  
  1009.    Features are normally named after the files they are provided in
  1010. so that `require' need not be given the file name.
  1011.  
  1012.    For example, in `emacs/lisp/prolog.el',  the definition for
  1013. `run-prolog' includes the following code:
  1014.  
  1015.      (interactive)
  1016.      (require 'shell)
  1017.      (switch-to-buffer (make-shell "prolog" "prolog"))
  1018.      (inferior-prolog-mode))
  1019.  
  1020. The expression `(require 'shell)' loads the file `shell.el' if it has
  1021. not yet been loaded.  This ensures that `make-shell' is defined.
  1022.  
  1023.    The `shell.el' file contains the following top-level expression:
  1024.  
  1025.      (provide 'shell)
  1026.  
  1027. This adds `shell' to the global `features' list when the `shell' file
  1028. is loaded, so that `(require 'shell)' will henceforth know that
  1029. nothing needs to be done.
  1030.  
  1031.    When `require' is used at top-level in a file, it takes effect if
  1032. you byte-compile that file (*note Byte Compilation::.).  This is in
  1033. case the required package contains macros that the byte compiler must
  1034. know about.
  1035.  
  1036.    Although top-level calls to `require' are evaluated during byte
  1037. compilation, `provide' calls are not.  Therefore, you can ensure that
  1038. a file of definitions is loaded before it is byte-compiled by
  1039. including a `provide' followed by a `require' for the same feature,
  1040. as in the following example.
  1041.  
  1042.      (provide 'my-feature)  ; Ignored by byte compiler, evaluated by `load'.
  1043.      (require 'my-feature)  ; Evaluated by byte compiler.
  1044.  
  1045.   * Function: provide FEATURE
  1046.      This function announces that FEATURE is now loaded, or being
  1047.      loaded, into the current Emacs session.  This means that the
  1048.      facilities associated with FEATURE are or will be available for
  1049.      other Lisp programs.
  1050.  
  1051.      The direct effect of calling `provide' is to add FEATURE to the
  1052.      front of the list `features' if it is not already in the list. 
  1053.      The argument FEATURE must be a symbol.  `provide' returns FEATURE.
  1054.  
  1055.           features
  1056.                => (bar bish)
  1057.           
  1058.           (provide 'foo)
  1059.                => foo
  1060.           features
  1061.                => (foo bar bish)
  1062.  
  1063.      During autoloading, if the file is not completely loaded (due to
  1064.      an error in the evaluation of the contents) any function
  1065.      definitions or `provide' calls that occurred during the load are
  1066.      undone.  *Note Autoload::.
  1067.  
  1068.  * Function: require FEATURE &optional FILENAME
  1069.      This function checks whether FEATURE is present in the current
  1070.      Emacs session (using `(featurep FEATURE)'; see below).  If it is
  1071.      not, then `require' loads FILENAME with `load'.  If FILENAME is
  1072.      not supplied, then the name of the symbol FEATURE is used as the
  1073.      file name to load.
  1074.  
  1075.      If FEATURE is not provided after the file has been loaded, Emacs
  1076.      will signal the error `error' (with data `Required feature
  1077.      FEATURE was not provided').
  1078.  
  1079.  * Function: featurep FEATURE
  1080.      This function returns `t' if FEATURE has been provided in the
  1081.      current Emacs session (i.e., FEATURE is a member of `features'.)
  1082.  
  1083.  * Variable: features
  1084.      The value of this variable is a list of symbols that are the
  1085.      features loaded in the current Emacs session.  Each symbol was
  1086.      put in this list with a call to `provide'.  The order of the
  1087.      elements in the `features' list is not significant.
  1088.  
  1089.  
  1090. 
  1091. File: elisp,  Node: Byte Compilation,  Next: Debugging,  Prev: Loading,  Up: Top
  1092.  
  1093. Byte Compilation
  1094. ****************
  1095.  
  1096.    GNU Emacs Lisp has a "compiler" that translates functions written
  1097. in Lisp into a special representation called "byte-code" that can be
  1098. executed more efficiently.  The compiler replaces Lisp function
  1099. definitions with byte-code.  When a byte-code function is called, its
  1100. definition is evaluated by the "byte-code interpreter".
  1101.  
  1102.    Because the byte-compiled code is evaluated by the byte-code
  1103. interpreter, instead of being executed directly by the machine's
  1104. hardware (as true compiled code is), byte-code is completely
  1105. transportable from machine to machine without recompilation.  It is
  1106. not, however, as fast as true compiled code.
  1107.  
  1108.    *Note Compilation Errors::, for how to investigate errors
  1109. occurring in byte compilation.
  1110.  
  1111. * Menu:
  1112.  
  1113. * Compilation Functions::       Byte compilation functions.
  1114. * Disassembly::                 Disassembling byte-code; how to read byte-code.
  1115.  
  1116.  
  1117. 
  1118. File: elisp,  Node: Compilation Functions,  Next: Disassembly,  Prev: Byte Compilation,  Up: Byte Compilation
  1119.  
  1120. The Compilation Functions
  1121. =========================
  1122.  
  1123.    An individual function or macro definition may be byte-compiled
  1124. with the `byte-compile' function.  A whole file may be byte-compiled
  1125. with `byte-compile-file' and several files may be byte-compiled with
  1126. `byte-recompile-directory' or `batch-byte-compile'.  Only `defun' and
  1127. `defmacro' forms in a file are byte-compiled; other top-level forms
  1128. are not altered by byte compilation.
  1129.  
  1130.    Be careful when byte-compiling code that uses macros.  Macro calls
  1131. are expanded when they are compiled, so the macros must already be
  1132. defined for proper compilation.  For more details, see *Note
  1133. Compiling Macros::.
  1134.  
  1135.    While byte-compiling a file, any `require' calls at top-level are
  1136. executed.  One way to ensure that necessary macro definitions are
  1137. available during compilation is to require the file that defines them.
  1138. *Note Features::.
  1139.  
  1140.    A byte-compiled function is not as efficient as a primitive
  1141. function written in C, but will run much faster than the version
  1142. written in Lisp.  For a rough comparison, consider the example below:
  1143.  
  1144.      (defun silly-loop (n)
  1145.        "Return time before and after N iterations of a loop."
  1146.        (let ((t1 (current-time-string)))
  1147.          (while (> (setq n (1- n)) 
  1148.                    0))
  1149.          (list t1 (current-time-string))))
  1150.      => silly-loop
  1151.      
  1152.      (silly-loop 100000)
  1153.      => ("Thu Jan 12 20:18:38 1989" 
  1154.          "Thu Jan 12 20:19:29 1989")  ; 51 seconds
  1155.      
  1156.      (byte-compile 'silly-loop)
  1157.      => [Compiled code not shown]
  1158.      
  1159.      (silly-loop 100000)
  1160.      => ("Thu Jan 12 20:21:04 1989" 
  1161.          "Thu Jan 12 20:21:17 1989")  ; 13 seconds
  1162.  
  1163.    In this example, the interpreted code required 51 seconds to run,
  1164. whereas the byte-compiled code required 13 seconds.  These results
  1165. are representative, but actual results will vary greatly.
  1166.  
  1167.  * Function: byte-compile SYMBOL
  1168.      This function byte-compiles the function definition of SYMBOL,
  1169.      replacing the previous definition with the compiled one.  The
  1170.      function definition of SYMBOL must be the actual code for the
  1171.      function; i.e., the compiler will not follow indirection to
  1172.      another symbol.  `byte-compile' does not compile macros. 
  1173.      `byte-compile' returns the new, compiled definition of SYMBOL.
  1174.  
  1175.           (defun factorial (integer)
  1176.             "Compute factorial of INTEGER."
  1177.             (if (= 1 integer) 1
  1178.               (* integer (factorial (1- integer)))))
  1179.                => factorial
  1180.           
  1181.           (byte-compile 'factorial)
  1182.                => (lambda (integer) 
  1183.                            "Compute factorial of INTEGER." 
  1184.                            (byte-code "\301^HU\203
  1185.           ^@\301\202^Q^@\302^H\303^HS!\"\207"
  1186.                                       [integer 1 * factorial] 4))
  1187.  
  1188.      The string that is the first argument of `byte-code' is the
  1189.      actual byte-code.  Each character in it is an instruction.  The
  1190.      vector contains all the constants, variable names and function
  1191.      names used by the function, except for certain primitives that
  1192.      are coded as special instructions.
  1193.  
  1194.      The `byte-compile' function is not autoloaded as are
  1195.      `byte-compile-file' and `byte-recompile-directory'.
  1196.  
  1197.  * Command: byte-compile-file FILENAME
  1198.      This function compiles a file of Lisp code named FILENAME into a
  1199.      file of byte-code.  The output file's name is made by appending
  1200.      `c' to the end of FILENAME.
  1201.  
  1202.      Compilation works by reading the input file one form at a time. 
  1203.      If it is a definition of a function or macro, the compiled
  1204.      function or macro definition is written out.  Other forms are
  1205.      copied out unchanged.  All comments are discarded when the input
  1206.      file is read.
  1207.  
  1208.      This command returns `t'.  When called interactively, it prompts
  1209.      for the file name.
  1210.  
  1211.           % ls -l push*
  1212.           -rw-r--r--  1 lewis             791 Oct  5 20:31 push.el
  1213.           
  1214.           (byte-compile-file "~/emacs/push.el")
  1215.                => t
  1216.           
  1217.           % ls -l push*
  1218.           -rw-r--r--  1 lewis             791 Oct  5 20:31 push.el
  1219.           -rw-rw-rw-  1 lewis             638 Oct  8 20:25 push.elc
  1220.  
  1221.  * Command: byte-recompile-directory DIRECTORY FLAG
  1222.      This function recompiles every `.el' file in DIRECTORY that
  1223.      needs recompilation.  A file needs recompilation if a `.elc'
  1224.      file exists but is older than the `.el' file.
  1225.  
  1226.      If a `.el' file exists, but there is no corresponding `.elc'
  1227.      file, then FLAG is examined.  If it is `nil', the file is
  1228.      ignored.  If it is non-`nil', the user is asked whether the file
  1229.      should be compiled.
  1230.  
  1231.      The returned value of this command is unpredictable.
  1232.  
  1233.  * Function: batch-byte-compile
  1234.      This function runs `byte-compile-file' on the files remaining on
  1235.      the command line.  This function must be used only in a batch
  1236.      execution of Emacs, as it kills Emacs on completion.  Each file
  1237.      will be processed, even if an error occurs while compiling a
  1238.      previous file.  (The file with the error will not, of course,
  1239.      produce any compiled code.)
  1240.  
  1241.           % emacs -batch -f batch-byte-compile *.el
  1242.  
  1243.  * Function: byte-code CODE-STRING DATA-VECTOR MAX-STACK
  1244.      This is the function that actually interprets byte-code.  A
  1245.      byte-compiled function is actually defined with a body that
  1246.      calls `byte-code'.  Don't call this function yourself.  Only the
  1247.      byte compiler knows how to generate valid calls to this function.
  1248.  
  1249.  
  1250.